Skip to content

move locks in TSRM.c to prevent races #8298

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

ryancaicse
Copy link
Contributor

move locks in TSRM.c to prevent races

move locks in TSRM.c to prevent races
@nikic
Copy link
Member

nikic commented Apr 4, 2022

Could you please provide more information on which race this is supposed to prevent?

@ryancaicse
Copy link
Contributor Author

Hi, it seems the method that is not thread-safe should be protected by locks. I just move the locks to protect the missed variables.

@krakjoe
Copy link
Member

krakjoe commented Apr 5, 2022

Could you please provide more information on which race this is supposed to prevent?

This could happen:

flowchart TD

A[X Enters ts_allocate_id]
B[Y Enters ts_allocate_id]

A --> C[X Releases Mutex in error path]
B --> D[Y Acquires Mutex and travels success path]

C --> R[Race for rsrc_id]
D --> R
Loading

Although it's not surprising we don't see this in the real world ...

In general the change makes sense to me, we otherwise only manipulate rsrc_id/offset inside critical sections, manipulating it outside does look wrong ...

@cmb69
Copy link
Member

cmb69 commented Apr 5, 2022

Since this appears to fix a potential bug, shouldn't this PR target PHP-8.0?

@krakjoe
Copy link
Member

krakjoe commented Apr 11, 2022

Since this appears to fix a potential bug, shouldn't this PR target PHP-8.0?

Yes

I did reply via email several days ago but the response seems to be missing.

@cmb69 cmb69 closed this in 1a75269 Apr 11, 2022
@krakjoe
Copy link
Member

krakjoe commented Oct 11, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants